const fs = require('fs');

export async function readLines(file) {
  return new Promise((resolve, reject) => {
    fs.open(file, 'r', function (err, fileToRead) {
      if (!err) {
        fs.readFile(fileToRead, { encoding: 'utf-8' }, function (e, data) {
          if (!e) {
            resolve(data.split('\n'));
            // console.log('received data: ' + data);
          } else {
            console.log(e);
            reject('Can not read file, error: ' + e);
          }
        });
      } else {
        console.log(err);
        reject('Can not open file, error: ' + err);
      }
    });
  });
}